// 两个接口
// 一个是 request 后缀是 api 的请求使用 request
// 一个是 serve 后缀是 ips 的请求使用 reque

import request from '@/utils/request'
// import serve from '@/utils/serve'

// 分页获取仓库 + 查询(精确查询)
export const getWarehousePage = (pageConfig, searchQuery) => {
  const params = { ...pageConfig }
  if (searchQuery) {
    const [code, name, status] = searchQuery
    if (code) params.code = code
    if (name) params.name = name
    params.status = status
  }
  return request.get('/warehouse/page', { params })
}

// 新增仓库时获取仓库编号
export const getWarehouseCode = () => request.get('/codeFactory/next/CK')

// 新增仓库
export const addWarehouse = (data) => request.post('/warehouse', data)

// 根据id获取仓库详情
export const getWarehouseDetails = (id) => request.get(`/warehouse/${id}`)

// 编辑仓库
export const editWarehouse = (data) => request.put('warehouse', data)

// 获取所有仓库
export const getWarehouseList = (status = '') =>
  status
    ? request.get(`/warehouse/list?status=${status}`)
    : request.get('/warehouse/list')

// 删除仓库
export const delWarehouse = (id) => request.delete('warehouse', { params: { ids: [id] }})
